﻿using System;
using mojoPortal.Web;
using mojoPortal.Web.Framework;
using Resources;

namespace ud_Forum
{
    public partial class ForumSearchBox : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((WebConfigSettings.DisableSearchFeatureFilters)||(WebConfigSettings.DisableSearchIndex))
            {
                Visible = false;
                return;
            }

            btnSearch.Text = ForumResources.Search;
            reqSearchText.ErrorMessage = ForumResources.SearchTermRequiredWarning;
        }

        void btnSearch_Click(object sender, EventArgs e)
        {
            string redirectUrl = Request.RawUrl;
            if (txtSearch.Text.Length > 0)
            {
                redirectUrl = SiteUtils.GetNavigationSiteRoot()
                    + "/SearchResults.aspx?f=D282E7D2-BAF9-4B44-B8CB-8D05872D4B25&q=" + Server.UrlEncode(txtSearch.Text);
            }

            WebUtils.SetupRedirect(this, redirectUrl);
            
        }

        //SearchResults.aspx?q=foo&f=D282E7D2-BAF9-4B44-B8CB-8D05872D4B25
        //btnSearch

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Load += Page_Load;
            btnSearch.Click += btnSearch_Click;
        }
    }
}